package NWish.properties.object3ds
{
	import NWish.Away3d;
	import NWish.Interface.ILogger;
	import NWish.Logger;
	import NWish.properties.FileProperties;
	
	import away3d.audio.Sound3D;
	import away3d.primitives.WireframeCube;
	
	public class Sound3DProperties extends ObjectContainer3DProperties
	{
		static public const extraFileName = 'meshFileName';
			
		public function Sound3DProperties(app)
		{
			super(app);
			
			var keys
			= 
				['volume'
				,'scaleDistance'
				,new FileProperties(app, extraFileName, ['.mp3'])
				];
			
			addPropertieKeys('Sound3D',keys);
			
			addPropertieKeys_read('Sound3D',['playing','paused']);
		}
		
		
		//
		override public function toString()
		{
			return 'Sound3D';
		}
		
		override public function get type()
		{
			return Sound3D;
		}
		
		override public function get createEnable()
		{
			return true;
		}
		
		//
		override public function newType(scene,dict)
		{
			if(dict == null)
				return new Sound3D(null,null);
			
			if(scene)
			{
				var file = dict['file'];
				
				if(file == '' || file == null)
				{
					ILogger.log('please select a mp3 file!');
					return;
				}
				
				var f = fileSystem.getResource(file);
				
				if(f)
				{
					var s3d:Sound3D = new Sound3D(f,camera);
					s3d.extra = new Object();
					s3d.extra[extraFileName] = file;
					
					//todo...
					//鼠标划过后播放音乐
					s3d.play();
					
					if(scene && s3d && _app && _app.isEditor)
					{
						var icon3d = new WireframeCube(10, 10, 10);
						icon3d.name = Away3d.SysIcon3d;
						s3d.addChild(icon3d);
					}
					return s3d;
				}
			}
		}
		
		public function get camera()
		{
			if(_app)
			{
				return _app.getPlugin('Away3d').camera;
			}
		}
		
	}
}

